package web.handle;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;

import ejb.manager.CityManager;

@ManagedBean
@ViewScoped
public class CityPropertiesBean {
	@EJB
	private CityManager cityManager;
	
	private double temp, pressure;
	
	private int x;
	private int y;
	
	private String positionName;

	public CityPropertiesBean(){
		HttpServletRequest req = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();		
		setX(Integer.parseInt(req.getParameter("x")));
		setY(Integer.parseInt(req.getParameter("y")));
	}
	
	public String getPositionName() {
		return positionName;
	}

	public void setPositionName(String positionName) {
		this.positionName = positionName;
	}
	
	public double getTemp() {
		temp = cityManager.approxTemp(x, y);
		return (int)temp;
	}

	public void setTemp(double temp) {
		this.temp = temp;
	}

	public double getPressure() {
		pressure = cityManager.approxPress(x, y);
		return (int)pressure;
	}

	public void setPressure(double pressure) {
		this.pressure = pressure;
	}	
	
	public int getX() {
		return x;
	}
	public void setX(int x){		
		this.x = x;
	}
	public int getY() {
		return y;
	}
	public void setY(int y) {
		this.y = y;
	}
	
}
